package com.itao.security;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

/**
 * @Title: SecAuthenticationSuccessHandler.java
 * @Description: 
 * @date 2014年3月13日 下午2:35:36
 */

public class SecAuthenticationSuccessHandler implements
		AuthenticationSuccessHandler {

	@Override
    public void onAuthenticationSuccess(HttpServletRequest request,
            HttpServletResponse response, Authentication auth)
            throws IOException, ServletException {        
        String f = request.getParameter("f");
        if (StringUtils.isNotEmpty(f)) {
//            if(f.equals("android")){
//                response.setCharacterEncoding("UTF-8");
//                response.getWriter().write("登录成功");
//            }
            
        }else{
            String ru = (String)request.getSession().getAttribute("ru");
            request.getSession().removeAttribute("ru");
            if(StringUtils.isNotEmpty(ru)){
            	System.out.println("========"+ru);
                response.sendRedirect(ru);
                //request.getRequestDispatcher(ru).forward(request, response);
            }else{
                //request.getRequestDispatcher("/account/user.exp").forward(request, response);
                request.getRequestDispatcher("/").forward(request, response);
            }
            
        }

    }


}
